const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  onLoad: function (options) {
    this.loadBanner()
    this.volunteer()
  },

  toVolunteerDetails(e){
    let service_id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../volunteer-details/volunteer-details?service_id=' + service_id,
    })
  },

  // 轮播图
  loadBanner(){
    wx.showLoading({
      title: '加载中...',
    })
    let access_token = wx.getStorageSync('access_token')
    wx.request({
      url: 'https://baokang.wshoto.com/wx/bannerlist',
      data:{
        access_token:access_token,
        location:'zhiyuan'
      },
      success:(res)=>{
        console.log(res.data)
        if(res.data.code >= 500){
          app.getLogin().then(function(){
            console.log('二次登录。。。')
          })
        } 
        else if(res.data.code == 1){
          this.setData({
            bannerList:res.data.list
          })
        } 
      },
      complete:(res)=>{
        wx.hideLoading()
      }
    })
  },

  volunteer(){
    let access_token = wx.getStorageSync('access_token')
    wx.request({
      url: 'https://baokang.wshoto.com/wx/volunteerlist',
      data:{
        access_token:access_token,
        volunteer_num:'-1'
      },
      success:(res)=>{
        console.log(res)
        if(res.data.code == 1){
          this.setData({
            service_list:res.data.info.service_list,
            people:res.data.info.total_sign,
            project:res.data.info.total_service
          })
        } 
      }
    })
  },

})